package com.hlhj.funlike_businessqzxd.moudle;

import android.content.Context;

import com.example.mymvp.mvp.BaseModule;
import com.hlhj.funlike_businessqzxd.api.Apis;
import com.hlhj.funlike_businessqzxd.api.BaseObser;
import com.hlhj.funlike_businessqzxd.bean.MsgBean;
import com.hlhj.funlike_businessqzxd.bean.ShopInfoBean;
import com.hlhj.funlike_businessqzxd.bean.TakeTypeBean;
import com.hlhj.funlike_businessqzxd.bean.UpImgBean;
import com.lzy.okgo.model.Response;

import java.io.File;
import java.util.List;

public class SettingsMoudle implements BaseModule{
    public interface getResult{
        void loadTimeResult(MsgBean msgBean);

        void loadTakeType(List<TakeTypeBean.DataBean> dataBeans);

        void loadSetTakeResult(MsgBean msgBean);

        void loadShopInfo(ShopInfoBean.DataBean dataBean);

        void loadUpImgResult(UpImgBean.DataBean dataBeans);
    }

    public getResult lisenter;

    public void setLisenter(getResult lisenter) {
        this.lisenter = lisenter;
    }

    public void LoadTimeResule(Context context,String business_start, String business_end){
        Apis.INSTANCE.ShopBusiness(business_start,business_end)
                .subscribe(new BaseObser<Response<MsgBean>>(context) {
                    @Override
                    public void httpSuccess(Response<MsgBean> msgBeanResponse) {
                        if (lisenter!=null){
                            lisenter.loadTimeResult(msgBeanResponse.body());
                        }
                    }
                });
    }

    public void LoadTakeType(Context context){
        Apis.INSTANCE.ShopGetTakeType()
                .subscribe(new BaseObser<Response<TakeTypeBean>>(context) {
                    @Override
                    public void httpSuccess(Response<TakeTypeBean> takeTypeBeanResponse) {
                        if (lisenter!=null){
                            lisenter.loadTakeType(takeTypeBeanResponse.body().getData());
                        }
                    }
                });
    }

    public void LoadSetTakeResult(Context context,int distribution,String freight,int freight_long){
        Apis.INSTANCE.ShopTakeType(distribution,freight,freight_long)
                .subscribe(new BaseObser<Response<MsgBean>>(context) {
                    @Override
                    public void httpSuccess(Response<MsgBean> msgBeanResponse) {
                        if (lisenter!=null){
                            lisenter.loadSetTakeResult(msgBeanResponse.body());
                        }
                    }
                });
    }

    public void LoadShopInfo(Context context){
        Apis.INSTANCE.ShopConfig()
                .subscribe(new BaseObser<Response<ShopInfoBean>>(context) {
                    @Override
                    public void httpSuccess(Response<ShopInfoBean> shopInfoBeanResponse) {
                        if (lisenter!=null){
                            lisenter.loadShopInfo(shopInfoBeanResponse.body().getData());
                        }
                    }
                });
    }

    public void LoadUpImgResult(Context context,File shop){
        Apis.INSTANCE.UpConverImg(shop)
                .subscribe(new BaseObser<Response<UpImgBean>>(context) {
                    @Override
                    public void httpSuccess(Response<UpImgBean> msgBeanResponse) {
                        if (lisenter!=null){
                            lisenter.loadUpImgResult(msgBeanResponse.body().getData());
                        }
                    }
                });
    }
}
